<!--
 * @Description: 余料信息
-->
<template>
    <el-dialog v-dialogDrag :visible="visible" title="翻料结果确认" width="800px" @close="onClose" @open="onOpen">
        请确定翻入信息：
        <BlockText :config="textConfig" :detail="detail" />
        <span slot="footer" class="dialog-footer">
            <el-button class="bottom_all_two" @click="onClose">取 消</el-button>
            <el-button class="bottom_all" type="primary" @click="onConfirm">确 定</el-button>
        </span>
    </el-dialog>
</template>

<script>
    import BlockText from './BlockText'
    import { turnoverTreatment } from '@/api/smart/schedul/k.js'
    export default {
        components: {
            BlockText
        },
        data() {
            return {
                textConfig: [
                    { label: '车牌号', field: 'carNo'},
                    { label: '生产站点', field: 'stationName'},
                    { label: '余料量', field: 'outCount'},
                    { label: '强度等级', field: 'strengthGradeId'},
                    { label: '性能等级', field: 'performanceGradeId'},
                    { label: '材料要求', field: 'meterialRequirementsId'},
                    { label: '特殊要求', field: 'specialRequirementsId'},
                    { label: '其他要求', field: 'otherRequirementsId'},
                    { label: '外加剂要求', field: 'admixtureRequirements'},
                ],
                detail: {},
            };
        },
        props: {
            config: {
                type: Object,
                default: () => ({}),
            },
            visible: {
                type: Boolean,
            },
        },
        methods: {
            onOpen() {
                const obj = {
                    carNo: this.config.carNo || '',
                    stationName: this.config.stationName || '',
                    outCount: this.config.outCount || 0,
                    strengthGradeId: this.config.strengthGradeId || '',
                    performanceGradeId: JSON.parse(this.config.performanceGradeId).map(item=>item.name).join(','),
                    meterialRequirementsId: JSON.parse(this.config.meterialRequirementsId).map(item=>item.name).join(','),
                    specialRequirementsId: JSON.parse(this.config.specialRequirementsId).map(item=>item.name).join(','),
                    otherRequirementsId: JSON.parse(this.config.otherRequirementsId).map(item=>item.name).join(','),
                    admixtureRequirements: JSON.parse(this.config.admixtureRequirements).map(item=>item.name).join(',')
                }
                this.detail = obj;
            },
            onClose() {
                this.$emit("update:visible", false)
            },
            async onConfirm() {
                turnoverTreatment(this.config).then(res=>{
                    if(res && res.code === 1001) {
                        this.$message.success("处理成功")
                        this.$emit("updated", false)
                        this.$emit("update:visible", false)
                    }
                })
            },
        },
    };
</script>
<style lang="scss"></style>